package idiet.dao.hibernate;

import idiet.bean.Resource;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("resourceDao")
public class ResourceDao extends BaseDao {
	public Resource getResourceById(int resourceId){
		return (Resource) this.sessionFactory
				.getCurrentSession()
				.createCriteria(Resource.class)
				.add(Restrictions.eq("id", resourceId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<Resource> getResourcesByResourceName(String name){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Resource.class)
				.add(Restrictions.like("name",name))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Resource> getResources(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Resource.class)
				.list();
	}
	public void createResource(Resource resource){
		this.sessionFactory
		.getCurrentSession()
		.save(resource);
	}
	public void updateResource(Resource resource){
		this.sessionFactory
		.getCurrentSession()
		.update(resource);
	}
	public void deleteResource(Resource resource){
		this.sessionFactory
		.getCurrentSession()
		.delete(resource);
	}
}
